import Rx from "rxjs"

let foo = Rx.Observable.create(observer => {
    observer.next(6);
    observer.next(6);
})

foo.simulatorScan = function (fn, seed) {
    //外层没有subscribe，里层的subscribe也不会被调用，层层倒退，使得最初的那个observable不会被调用
    return Rx.Observable.create(observer => {
        var acc;
        if (!acc) {
            acc = seed;
        }
        this.subscribe({
            next: value => {
                console.log("simulator scan:" + value);
                acc=fn(acc,value);
                observer.next(acc);
            }
        })
    });
}

foo.simulatorScan((y, x) => y + x, 0).subscribe(function (value) {
    console.log(value);
})